package com.yc.common.utils.email;

import java.time.LocalDate;

/**
 * 邮件模板工具类
 *
 * @Author YanChen
 * @Date 2025/4/24 12:08
 **/
public class EmailTemplateUtil {

    /**
     * 创建带有CID引用的邮件HTML内容，兼容各种邮箱
     *
     * @param subject 邮件主题
     * @param cid     内嵌图片的Content-ID（不含"cid:"前缀）
     * @return HTML内容
     */
    public static String createEmailHtmlWithCid(String subject, String cid) {
        StringBuilder html = new StringBuilder();
        html.append("<!DOCTYPE html>");
        html.append("<html>");
        html.append("<head>");
        html.append("<meta charset='UTF-8'>");
        html.append("<meta name='viewport' content='width=device-width, initial-scale=1.0'>");
        html.append("<style>");
        // 基本样式
        html.append("  body { font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; line-height: 1.6; color: #333; margin: 0; padding: 0; background-color: #f7f7f7; }");
        html.append("  .email-container { max-width: 600px; margin: 20px auto; background-color: #ffffff; border-radius: 8px; overflow: hidden; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }");
        html.append("  .email-header { background-color: #4285f4; color: white; padding: 20px 30px; text-align: center; }");
        html.append("  .email-header h1 { margin: 0; font-size: 24px; font-weight: 500; }");
        html.append("  .email-body { padding: 30px; text-align: center; }");
        html.append("  .email-body p { margin-bottom: 20px; color: #555; font-size: 16px; }");
        // 验证码容器样式
        html.append("  .captcha-container { background-color: #f9f9f9; border-radius: 6px; padding: 20px; margin: 20px 0; border: 1px solid #e0e0e0; }");
        html.append("  .captcha-image { display: block; max-width: 100%; height: auto; margin: 0 auto; border: 1px solid #ddd; border-radius: 4px; }");
        // 底部样式
        html.append("  .email-footer { background-color: #f5f5f5; padding: 15px; text-align: center; color: #999; font-size: 12px; }");
        // 响应式调整
        html.append("  @media screen and (max-width: 600px) { .email-container { width: 100% !important; margin: 0 !important; } .email-body, .email-header { padding: 15px !important; } }");
        html.append("</style>");
        html.append("</head>");
        html.append("<body>");
        html.append("<div class='email-container'>");
        // 邮件头部
        html.append("  <div class='email-header'>");
        html.append("    <h1>" + subject + "</h1>");
        html.append("  </div>");
        // 邮件主体
        html.append("  <div class='email-body'>");
        html.append("    <p>您好，下方是您的验证码，请在页面中输入以完成验证：</p>");
        // 验证码图片容器
        html.append("    <div class='captcha-container'>");
        html.append("      <img src='cid:" + cid + "' alt='验证码' class='captcha-image' />");
        html.append("    </div>");
        html.append("    <p>如果这不是您请求的操作，请忽略此邮件。</p>");
        html.append("  </div>");
        // 邮件底部
        html.append("  <div class='email-footer'>");
        html.append("    <p>© " + LocalDate.now().getYear() + " 您的公司名称. 保留所有权利。</p>");
        html.append("  </div>");
        html.append("</div>");
        html.append("</body>");
        html.append("</html>");

        return html.toString();
    }
}